<template>
  <div id="app">
    <div class="container">
      <div class="close"><span class="iconfont iconicon-test"></span></div>
      <div class="logo"><span class="iconfont iconnew"></span></div>
      <div class="inputs">
        <hemaInput
          ref="username"
          v-model="user.username"
          placeholder="手机号"
          :reg="
            /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/
          "
          type="text"
        ></hemaInput>
        <hemaInput
          ref="nickname"
          v-model="user.nickname"
          placeholder="昵称"
          :reg="/^.{1,14}$/"
          type="text"
        ></hemaInput>
        <hemaInput
          ref="password"
          v-model="user.password"
          placeholder="密码"
          :reg="/^.{3,14}$/"
          type="password"
        ></hemaInput>
      </div>
      <p class="tips">
        有账号？
        <a href="#/login" class="">去登录</a>
      </p>
      <van-button
        round
        type="info"
        size="large"
        color="#099435"
        @click="singInFn"
        ><van-icon name="star-o" />注册</van-button
      >
    </div>
  </div>
</template>

<script>
import hemaInput from "@/components/hemaInput.vue";
import { singIn } from "@/apis/get.js";
export default {
  data() {
    return {
      user: {
        username: "17673849042",
        password: "",
        nickname: "",
      },
    };
  },
  components: {
    hemaInput,
  },
  methods: {
    singInFn() {
      let { username, nickname, password } = this.$refs;
      if (!username.flag || !password.flag || !nickname.flag) {
        this.$toast.fail("信息有误");
        return;
      } else {
        singIn(this.user).then((res) => {
          this.$toast(res.data.message);
          if (res.data.message == "注册成功") {
            this.$router.push({
              path: "/login",
            });
          }
          // console.log(res);
        });
      }
    },
  },
};
</script>

<style lang="less" scoped>
.container {
  padding: 20px;
}
.close {
  span {
    font-size: 27 / 360 * 100vw;
  }
}
.logo {
  display: flex;
  justify-content: center;

  span {
    display: block;
    font-size: 126 / 360 * 100vw;
    color: #d81e06;
  }
}
.inputs {
  input {
    margin-bottom: 20px;
  }
}
.tips {
  text-align: right;
  margin-bottom: 20px;
  a {
    color: #3385ff;
  }
}
</style>